//
// Created by Administrator on 25-5-13.
//

#ifndef RENDERENGINE_H
#define RENDERENGINE_H

#include <glad/glad.h>
#include <GLFW/glfw3.h>

#include <chrono>

#include "Camera.h"
#include "Model.h"
#include "Shader.h"
#include "setting.h"

class RenderEngine
{
public:
	RenderEngine();

	~RenderEngine();

	void Run();

private:
	static RenderEngine *instance;
	GLFWwindow *window;
	std::unique_ptr<Camera> camera;
	unsigned int planeVAO;
	unsigned int modelVAO;
	unsigned int lightVAO;
	std::unique_ptr<Shader> litShader;
	std::unique_ptr<Shader> lightShader;
	std::unique_ptr<Material> litMaterial;
	std::unique_ptr<Material> lightMaterial;
	unsigned int diffuseMap;
	unsigned int specularMap;
	unsigned int floorTexture;
	std::unique_ptr<Model> model;

	double lastX = SCR_WIDTH / 2.0f;
	double lastY = SCR_HEIGHT / 2.0f;
	bool firstMouse = true;
	bool mouseRightPressed = false;

	double lastFrameTime = 0.00f;
	int frameCount = 0;
	double deltaTime = 0.00f;
	bool shouldClose = false;

	unsigned int framebuffer;
	unsigned int screenQuadVAO;
	std::unique_ptr<Shader> framebufferShader;
	unsigned int colorbufferTexture;

	void InitFramebuffer();

	void RenderLoop();

	void ProcessInput() const;

	void CalculateDeltaTimeAndFPS();

	void Rendering() const;

	static unsigned int LoadTexture(char const *path);
	static void LoadCubeMap(char const *path);
};

#endif  // RENDERENGINE_H
